package com.xii.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xii.entity.PageResult;
import com.xii.entity.QueryPageBean;
import com.xii.mapper.CheckItemMapper;
import com.xii.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * @description: 新增检查项
     *
     * @author  wangxihao
     * @email wangxh0108@163.com
    **/
    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    /**
     * @description: 分页查询
     *
     * @author  wangxihao
     * @email wangxh0108@163.com
    **/
    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        //分页插件执行分页   当前页和每页条数
        PageHelper.startPage(pageBean.getCurrentPage(),pageBean.getPageSize());
        List<CheckItem> checkItemList = checkItemMapper.findPage(pageBean.getQueryString());
        //传入查询出来的所有值 进行分页操作
        PageInfo<CheckItem> pageInfo  = new PageInfo<>(checkItemList);
        //返回总页数和当前页
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * @description: 删除检查项
     *
     * @author  wangxihao
     * @email wangxh0108@163.com
    **/
    @Override
    public void delete(Integer id) {
        checkItemMapper.delete(id);
    }

    /**
     * @description: 查新检查项
     *
     * @author  wangxihao
     * @email wangxh0108@163.com
    **/
    @Override
    public  CheckItem  findById(Integer id) {
        CheckItem checkItem = checkItemMapper.findById(id);
        return checkItem;
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }
}
